package com.doit.day04

object _09_边缘算子 {
  def main(args: Array[String]): Unit = {
    //mapValues
    val map: Map[Int, String] = Map((1, "zss"), (2, "lss"), (3, "ww"))

    map.map(tp=>(tp._1,tp._2.toUpperCase()))
      .foreach(println)

    //针对value进行操作
    map.mapValues(_.toUpperCase())
      .foreach(println)


    //归约
/*    val list: List[Int] = List(1, 2, 3, 4, 5)
    //fold  ==》 做折叠
    /**
     * 第一个参数传的是默认值
     * 第二个参数传的是计算函数
     */
    val i: Int = list.fold(10)((a:Int,b:Int)=>a+b)
    println(i)*/


/*    val res: Int = list.reduce((a: Int, b: Int) => a + b)
    val res0: Int = list.reduce(_+_)
    println(res)

    val res1: Int = list.reduceRight((a: Int, b: Int) => a + b)
    println(res1)

    val res2: Int = list.reduceRight((a: Int, b: Int) => a - b)
    println(res2)//3*/


    //zip
    val list: List[Int] = List(1, 2, 3, 4, 5)
    val list1: List[Int] = List(10, 20, 30, 40, 50)
    val tuples: List[(Int, Int)] = list.zip(list1)
    println(tuples)

    val index: List[(Int, Int)] = list1.zipWithIndex
    println(index)//List((10,0), (20,1), (30,2), (40,3), (50,4))



    //滑动
    val iterator: Iterator[List[Int]] = list.sliding(2,3)
    while (iterator.hasNext) println(iterator.next())

    val ints: List[Int] = list.slice(1, 3)
//    println(ints)












  }

}
